var searchSort = "near";
var searchPage = 1;
var isClickPageBtnToSearch = false;

String.prototype.format = function () {
    var result = this;
    if (arguments.length > 0) {    
        if (arguments.length == 1 && typeof (args) == "object") {
            for (var key in args) {
                if(args[key]!=undefined){
                    var reg = new RegExp("({" + key + "})", "g");
                    result = result.replace(reg, args[key]);
                }
            }
        }
        else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] != undefined) {
　　　　　　　　　　　　var reg= new RegExp("({)" + i + "(})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
    }
    return result;
}

function second_to_hs(s) {
    var m = Math.floor(s / 60);//分钟
    var second = s % 60;    //秒
    var s = Math.floor(second);
    var hs = second - s;
    m += '';
    s += '';
    m = (m.length == 1) ? '0' + m : m;
    s = (s.length == 1) ? '0' + s : s;
    return m + ':' + s + '.' + Math.floor(hs * 1000);
}


function keepTwoDecimal(num) {
    var result = parseFloat(num);
    if (isNaN(result)) {
    alert('传递参数错误，请检查！');
    return false;
    }
    result = Math.round(num * 100) / 100;
    return result;
   }
   //四舍五入保留2位小数（不够位数，则用0替补）
   function keepTwoDecimalFull(num) {
    var result = parseFloat(num);
    if (isNaN(result)) {
    alert('传递参数错误，请检查！');
    return false;
    }
    result = Math.round(num * 100) / 100;
    var s_x = result.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
    pos_decimal = s_x.length;
    s_x += '.';
    }
    while (s_x.length <= pos_decimal + 2) {
    s_x += '0';
    }
    return s_x;
   }
   function  getPoint(id){  //返回html控件的坐标
    var htmlObj = document.getElementById(id);
    var  rd  =  {x:0,y:0};
    do{
        rd.x  +=  htmlObj.offsetLeft;
        rd.y  +=  htmlObj.offsetTop;
        htmlObj  =  htmlObj.offsetParent;
    }
    while(htmlObj)
    return  rd;
}


function SetupPagination(totalCount,pageCount) {
    new Page({
        id: 'pagination',
        pageTotal: Math.ceil(totalCount / pageCount), //必填,总页数
        pageAmount: pageCount,  //每页多少条
        dataTotal: totalCount, //总共多少条数据
        curPage: 1, //初始页码,不填默认为1
        pageSize: 15, //分页个数,不填默认为5
        showPageTotalFlag: true, //是否显示数据统计,不填默认不显示
        showSkipInputFlag: true, //是否支持跳转,不填默认不显示
        getPage: function (page) {
            //获取当前页数
            searchPage = page;
            RequestSearch();
            isClickPageBtnToSearch = true;
        }
    });
}

